package com.dong.springbootdruidmultiple.config;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * Description: new java files header..
 *
 * @author DJ
 * @version 1.0
 * @date 2023/8/3 14:27
 */
@Configuration
public class DataSourceConfig {

    /**
     * 创建orders数据源
     *
     * @return javax.sql.DataSource
     * @author DJ
     * @date 2023/8/3 14:31
     */
    @Primary
    @Bean(name = "ordersDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.orders")
    public DataSource ordersDataSource() {
        return DruidDataSourceBuilder.create().build();
    }


    /**
     * 创建users数据源
     *
     * @return javax.sql.DataSource
     * @author DJ
     * @date 2023/8/3 14:33
     */
    @Bean(name = "usersDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.users")
    public DataSource usersDataSource() {
        return DruidDataSourceBuilder.create().build();
    }

}
